package com.bnz.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {

    //1. 用户登录
    @PostMapping("/login")
    public String login(String username, String password, HttpSession session){
        //1.1 假设数据库中的用户名为张三,密码为123
        if("张三".equals(username) && "123".equals(password)){
            //1.2 将用户信息保存到session中
            session.setAttribute("username",username);
            //1.3 跳转到成功页面
            return "success";
        }
        //1.4 否则，跳转到登录页面
        return "redirect:/login.jsp";
    }
}
